﻿using System.Collections.Generic;
using System.ServiceModel;
using Silent.MDB.Common.Data;
using Silent.MDB.Common.Services;
using Silent.WCF.Base;

namespace Silent.MDB.Server.Model.Services
{
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single,
        InstanceContextMode = InstanceContextMode.Single,
        IncludeExceptionDetailInFaults = true)]
    public class ServiceManager : ServiceManagerBase,
        ISystemInfoService,
        IRepositoryService<RootObject>,
        IRepositoryService<Folder>,
        IRepositoryService<Person>,
        IRepositoryService<Student>,
        IRepositoryService<Teacher>,
        IRepositoryService<Department>,
        IRepositoryService<Cathedra>,
        IRepositoryService<Faculty>
    {
        public override void Initialize()
        {
            AddService(new SystemInfoServiceBase());
            AddService(new RepositoryServiceBase<RootObject>());
            AddService(new RepositoryServiceBase<Folder>());
            AddService(new RepositoryServiceBase<Person>());
            AddService(new RepositoryServiceBase<Student>());
            AddService(new RepositoryServiceBase<Teacher>());
            AddService(new RepositoryServiceBase<Department>());
            AddService(new RepositoryServiceBase<Faculty>());
            AddService(new RepositoryServiceBase<Cathedra>());
        }

        #region ISystemInfoService Implementation

        public List<string> GetLocations()
        {
            return GetService<ISystemInfoService>().GetLocations();
        }

        public int GetLastId(string location)
        {
            return GetService<ISystemInfoService>().GetLastId(location);
        }

        #endregion

        #region IRepositoryService<RootObject> Implementation

        public void Add(RootObject item, string location)
        {
            GetService<IRepositoryService<RootObject>>().Add(item, location);
        }

        public void Update(RootObject item, string location)
        {
            GetService<IRepositoryService<RootObject>>().Update(item, location);
        }

        public void Remove(RootObject item, string location)
        {
            GetService<IRepositoryService<RootObject>>().Remove(item, location);
        }

        public ICollection<RootObject> Load(RootObject filter, string location)
        {
            return GetService<IRepositoryService<RootObject>>().Load(filter, location);
        }

        public void Save(ICollection<RootObject> data, string location)
        {
            GetService<IRepositoryService<RootObject>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Folder> Implementation

        public void Add(Folder item, string location)
        {
            GetService<IRepositoryService<Folder>>().Add(item, location);
        }

        public void Update(Folder item, string location)
        {
            GetService<IRepositoryService<Folder>>().Update(item, location);
        }

        public void Remove(Folder item, string location)
        {
            GetService<IRepositoryService<Folder>>().Remove(item, location);
        }

        public ICollection<Folder> Load(Folder filter, string location)
        {
            return GetService<IRepositoryService<Folder>>().Load(filter, location);
        }

        public void Save(ICollection<Folder> data, string location)
        {
            GetService<IRepositoryService<Folder>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Person> Implementation

        public void Add(Person item, string location)
        {
            GetService<IRepositoryService<Person>>().Add(item, location);
        }

        public void Update(Person item, string location)
        {
            GetService<IRepositoryService<Person>>().Update(item, location);
        }

        public void Remove(Person item, string location)
        {
            GetService<IRepositoryService<Person>>().Remove(item, location);
        }

        public ICollection<Person> Load(Person filter, string location)
        {
            return GetService<IRepositoryService<Person>>().Load(filter, location);
        }

        public void Save(ICollection<Person> data, string location)
        {
            GetService<IRepositoryService<Person>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Student> Implementation

        public void Add(Student item, string location)
        {
            GetService<IRepositoryService<Student>>().Add(item, location);
        }

        public void Update(Student item, string location)
        {
            GetService<IRepositoryService<Student>>().Update(item, location);
        }

        public void Remove(Student item, string location)
        {
            GetService<IRepositoryService<Student>>().Remove(item, location);
        }

        public ICollection<Student> Load(Student filter, string location)
        {
            return GetService<IRepositoryService<Student>>().Load(filter, location);
        }

        public void Save(ICollection<Student> data, string location)
        {
            GetService<IRepositoryService<Student>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Teacher> Implementation

        public void Add(Teacher item, string location)
        {
            GetService<IRepositoryService<Teacher>>().Add(item, location);
        }

        public void Update(Teacher item, string location)
        {
            GetService<IRepositoryService<Teacher>>().Update(item, location);
        }

        public void Remove(Teacher item, string location)
        {
            GetService<IRepositoryService<Teacher>>().Remove(item, location);
        }

        public ICollection<Teacher> Load(Teacher filter, string location)
        {
            return GetService<IRepositoryService<Teacher>>().Load(filter, location);
        }

        public void Save(ICollection<Teacher> data, string location)
        {
            GetService<IRepositoryService<Teacher>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Department> Implementation

        public void Add(Department item, string location)
        {
            GetService<IRepositoryService<Department>>().Add(item, location);
        }

        public void Update(Department item, string location)
        {
            GetService<IRepositoryService<Department>>().Update(item, location);
        }

        public void Remove(Department item, string location)
        {
            GetService<IRepositoryService<Department>>().Remove(item, location);
        }

        public ICollection<Department> Load(Department filter, string location)
        {
            return GetService<IRepositoryService<Department>>().Load(filter, location);
        }

        public void Save(ICollection<Department> data, string location)
        {
            GetService<IRepositoryService<Department>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Faculty> Implementation

        public void Add(Faculty item, string location)
        {
            GetService<IRepositoryService<Faculty>>().Add(item, location);
        }

        public void Update(Faculty item, string location)
        {
            GetService<IRepositoryService<Faculty>>().Update(item, location);
        }

        public void Remove(Faculty item, string location)
        {
            GetService<IRepositoryService<Faculty>>().Remove(item, location);
        }

        public ICollection<Faculty> Load(Faculty filter, string location)
        {
            return GetService<IRepositoryService<Faculty>>().Load(filter, location);
        }

        public void Save(ICollection<Faculty> data, string location)
        {
            GetService<IRepositoryService<Faculty>>().Save(data, location);
        }

        #endregion

        #region IRepositoryService<Cathedra> Implementation

        public void Add(Cathedra item, string location)
        {
            GetService<IRepositoryService<Cathedra>>().Add(item, location);
        }

        public void Update(Cathedra item, string location)
        {
            GetService<IRepositoryService<Cathedra>>().Update(item, location);
        }

        public void Remove(Cathedra item, string location)
        {
            GetService<IRepositoryService<Cathedra>>().Remove(item, location);
        }

        public ICollection<Cathedra> Load(Cathedra filter, string location)
        {
            return GetService<IRepositoryService<Cathedra>>().Load(filter, location);
        }

        public void Save(ICollection<Cathedra> data, string location)
        {
            GetService<IRepositoryService<Cathedra>>().Save(data, location);
        }

        #endregion
    }
}
